package conMgr.model;

import conMgr.util.ObservableList;

/**
 * User class that determine user type.
 */
public class User implements Comparable<User>
{
	/**
	 * Name of the user.
	 */
	private String name;
	
	/**
	 * User's email address.
	 */
	private String email;
	
	/**
	 * The type of the user.
	 */
	private UserType type;
	
	/**
	 * The current user.
	 */
	private static User currentUser;
	
	/**
	 * A list of all users.
	 */
	private static ObservableList<User> listOfAllUsers = new ObservableList<User>();
	
	/**
	 * A list of the reviewer's conferences.
	 */
	private ObservableList<Conference> reivewerConferences = new ObservableList<Conference>();
	
	/**
	 * A list of subprogram chair's conferences.
	 */
	private ObservableList<Conference> subprogramChairConferences = new ObservableList<Conference>();
	
	/**
	 * A list of the program chair's conferences.
	 */
	private ObservableList<Conference> programChairConferences = new ObservableList<Conference>();
	
	/**
	 * A list of the autor's papers.
	 */
	private ObservableList<Paper> authorPapers = new ObservableList<Paper>();
	
	/**
	 *A list of the autor's papers.
	 */
	private ObservableList<Paper> suprogramChairPapers = new ObservableList<Paper>();
	
	/**
	 * A list of the autor's papers.
	 */
	private ObservableList<Review> listOfUserReviews = new ObservableList<Review>();
		
	/**
	 * Constructor for the user object.
	 * @param name is name of the user.
	 * @param email is email of the user.
	 * @param type is type of the user.
	 */
	public User(String name, String email, UserType type)
	{
		 this.name = name;
		 this.email = email;
		 this.type = type; 
		 listOfAllUsers.add(this);
	}
	
	/**
	 * Returns user's name.
	 * @return name
	 */
	public String getName()
	{
		return this.name;
	}
	
	/**
	 * Returns user's email.
	 * @return email
	 */
	public String getEmail()
	{
		return this.email;
	}
	
	/**
	 * Returns user's type.
	 * @return type
	 */
	public UserType getType()
	{
		return this.type;
	}
	
	public static UserType getCurrentType()
	{		
		return currentUser.type;	
	}
	
	public void setCurrentType(UserType the_type)
	{
		type = the_type;
	}
	
	/**
	 * Returns the current user.
	 * @return currentUser
	 */
	public static User getCurrentUser()
	{	
		if (currentUser == null) {
			throw new IllegalStateException("No user is currently signed in");
		}	
		return currentUser;	
	}
	
	/**
	 * Returns the list of all users.
	 * @return listOfAllUsers
	 */
	public static ObservableList<User> getAllUsers()
	{		            
		return listOfAllUsers;
	}
	
	/**
	 * Returns a list of the reviewr's conferences.
	 * @return reivewerConferences
	 */
	public ObservableList<Conference> getReivewerConferences()
	{
		return reivewerConferences;
	}
	
	/**
	 * Returns a list of the subprogram chair's conferences.
	 * @return subprogramChairConferences.
	 */
	public ObservableList<Conference> getSubprogramChairConferences()
	{
		return subprogramChairConferences;
	}
	
	/**
	 * Returns a list of the program chair's conferences.
	 * @return programChairConferences.
	 */
	public ObservableList<Conference> getProgramChairConferences()
	{
		return programChairConferences;
	}
	
	/**
	 * Returns a list of papers of this author.
	 * @return authorPapers
	 */
	public ObservableList<Paper> getAuthorPapers()
	{
		return authorPapers;
	}
	
	/**
	 * Returns a list of papers of this subprogram chair.
	 * @return suprogramChairPapers.
	 */
	public ObservableList<Paper> getSuprogramChairPapers()
	{
		return suprogramChairPapers;
	}
	
	/**
	 * Returns a list of reviews of this user.
	 * @return listOfUserReviews
	 */
	public ObservableList<Review> getUserReviews()
	{
		return listOfUserReviews;
		
	}
	
	/**
	 * Sets the current user
	 * @param the_user is the current user
	 */
	public static void setCurrentUser(User the_user)
	{
		currentUser = the_user;
	}

	/**
	 * Compares this user to another user by name (alphabetically).
	 * @param otherUser The other user to compare to.
	 * -1 if this user should be sorted before the other user; 1 if the other
	 * user should be sorted before this user; 0 if they should be sorted the
	 * same. 
	 */
	@Override
	public int compareTo(User otherUser)
	{
		return name.compareTo(otherUser.name);
	}
}
